//
//  BaseCollectionController.m
//  oc1
//
//  Created by kokuma on 2017/2/11.
//  Copyright © 2017年 kokumams. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BaseCollectionController.h"
#import "AcgCell.h"
#import "AcgBean.h"
@interface BaseCollectionController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic,readwrite) CGFloat screen;
@end

@implementation BaseCollectionController
//CGFloat screen;

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //    添加myTableView
    _myCollectView = ({
        UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout alloc];
        _screen = [UIScreen mainScreen].bounds.size.width;
        layout.itemSize = CGSizeMake(_screen/2-20, _screen/2-20);
        layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);//设置内容的内边距
        layout.minimumInteritemSpacing = 1;//设置每个cell之间的最小间距
        //layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;//设置滚动方向
        UICollectionView *collectView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
        collectView.backgroundColor = [UIColor whiteColor];
        collectView.dataSource = self;
        collectView.delegate = self;
        collectView;
    });
    [self setupCells];
    [self.view addSubview:_myCollectView];
    [self getDataList];
}

//需要重载的方法
- (void)setupCells{
    [_myCollectView registerClass:[AcgCell class] forCellWithReuseIdentifier:kCellIdentifier_AcgCell];
}

//需要重载的方法
- (void)getDataList{
    printf("testAFNetworking1");
    MPNetAPIManager *netAPI = [MPNetAPIManager sharedManager];
    [netAPI getAcgsByKeyword:@"1" andBlock:^(id data, NSError *error) {
        if(data){
            NSMutableArray *accounts = data;
            if(!_dataList){
                _dataList = [NSMutableArray new];
            }
            [_dataList removeAllObjects];
            for(id openA in accounts){
                 //                AcgBean *bean = [[AcgBean alloc] initWithDictionary:openA];
                //                NSLog(bean.displayName);
                //                NSLog([@(bean.id.longValue) stringValue]);
                //               [_dataList addObject:bean];
            }
            [_myCollectView reloadData];
        }
    }];
}



//需要重载的方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    return nil;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if(_dataList){
        return _dataList.count;
    }else{
        return 0;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
